import authMenuList from '@/assets/json/authMenuList.json'
import authButtonList from '@/assets/json/authButtonList.json'
import http from '@/utils/request'
import type { UserInfo } from '@/api/account/index'

export interface ReqLoginForm {
  userName: string
  password: string
  branchCode: string
}
export interface ResLogin {
  token: string
  userinfo: UserInfo
}
export interface ResAuthButtons {
  [key: string]: string[]
}

/**
 * @name 登录模块
 */
// 用户登录
export const AuthApi = {
  login: (params: ReqLoginForm) => {
    return http.post<ResLogin>(`/auth/login`, params, { loading: false })
  },

  // 获取菜单列表
  getAuthMenuList: () => {
    // return http.get<MenuOptions[]>(`/user/menu`, {}, { loading: false })
    // 如果想让菜单变为本地数据，注释上一行代码，并引入本地 authMenuList.json 数据
    return authMenuList
  },

  // 获取按钮权限
  getAuthButtonList: () => {
    // return http.get<ResAuthButtons>(`/user/buttons`, {}, { loading: false })
    // 如果想让按钮权限变为本地数据，注释上一行代码，并引入本地 authButtonList.json 数据
    return authButtonList
  },

  // 用户退出登录
  logout: () => {
    return http.post(`/auth/logout`)
  },

  /**修改密码 */
  changePassword: (oldPassword: string, newPassword: string) => {
    return http.post('/auth/changePass', {
      newPassword,
      oldPassword,
    })
  },
}
